package logic

import (
	"context"
	"usershop/good_srv/goods"

	"usershop/api/internal/svc"
	"usershop/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddGoodsLogic) AddGoods(req *types.AddGoodsRequest) (resp *types.ResMsg, err error) {
	// todo: 添加商品

	_, err = l.svcCtx.GoodsSrv.GoodsCreate(l.ctx, &goods.CreateGoodsRequest{
		GoodsTitle:  req.GoodsTitle,
		GoodsPrice:  req.GoodsPrice,
		GoodsStock:  req.GoodsStock,
		GoodsStatus: req.GoodsStatus,
		GoodsCover:  req.GoodsCover,
	})
	if err != nil {
		return &types.ResMsg{
			Cre:  -1,
			Msg:  "新增失败",
			Data: nil,
		}, nil
	}

	return &types.ResMsg{
		Cre:  0,
		Msg:  "新增成功",
		Data: nil,
	}, nil
}
